#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 3;
int T, n, m, k, o, d[N], v[N], a[N], b[N], e[N], l[N];
bool f[N], ff[N], fff[N];
struct P
{
    int l, r;
};
void init()
{
    int cnt = 0;
    cin >> n >> m >> k >> o;
    for (int i = 1; i <= n; i++)
        cin >> d[i] >> v[i] >> a[i];
    for (int i = 1; i <= m; i++) cin >> b[i];
    sort(b + 1, b + m + 1);
    for (int i = 1; i <= n; i++)
    {
        if (v[i] <= o && a[i] <= 0) continue;
        if (a[i] == 0)
        {
            if (d[i] > b[m]) continue;
            cnt++;
            f[i] = 1;
            e[i] = k;
            continue;
        }
        double dis = (o * o - v[i] * v[i]) / 2.0 / a[i];
        double p = dis + d[i];
        if (v[i] > o)
        {
            if (d[i] > b[m]) continue;
            if (a[i] > 0)
            {
                cnt++;
                f[i] = 1;
                e[i] = k;
                continue;
            }
            for (int j = 1; j <= m; j++)
            {
                if (b[j] < d[i]) continue;
                if (b[j] >= d[i] && b[j] < p)
                {
                    cnt++;
                    f[i] = 1;
                    e[i] = p;
                    break;
                }
                if (b[j] > p) break;
            }
        }
        else
        {
            if (p >= b[m]) continue;
            cnt++;
            f[i] = 1;
            d[i] = p + 1;
            e[i] = k;
        }
    }
    vector<P> g;
    for (int i = 1; i <= n; i++)
    {
        if (f[i])
        {
            g.push_back({d[i], e[i]});
        }
    }
    int z = g.size(), zz = 0;
    for (int i = 0; i < z; i++) f[i] = 0;
    while (z)
    {
        for (int i = 1; i <= m; i++) l[i] = 0;
        for (int i = 0; i <= g.size(); i++)
        {
            if (f[i]) continue;
            for (int j = 1; j <= m; j++)
            {
                if (fff[j]) continue;
                if (g[i].l > b[j]) continue;
                if (g[i].l <= b[j] && b[j] <= g[i].r) l[j]++;
                if (b[j] > g[i].r) break;
            }
        }
        int mxid = 0;
        for (int i = 1; i <= m; i++)
        {
            if (fff[i]) continue;
            if (mxid == 0 || l[i] > l[mxid]) mxid = i;
        }
        fff[mxid] = 1;
        zz++;
        for (int i = 0; i <= g.size(); i++)
        {
            if (f[i]) continue;
            if (g[i].l <= b[mxid] && b[mxid] <= g[i].r)
            {
                f[i] = 1;
                z--;
            }
        }
    }

    cout << cnt << " " << m - zz << "\n";
}
signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    for (; T; T--) init();
    return 0;
}
/*
s = v0 * t + 0.5a t^2
v1 = sqrt(v0^2 + 2as)
s = (v1^2 - v0^2)/2a
*/
